package logic

import (
	"context"
	"shenzhou_srv/models"

	"shenzhou_srv/internal/svc"
	"shenzhou_srv/shenzhou"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartListLogic) CartList(in *shenzhou.CartListRequest) (*shenzhou.CartListResponse, error) {
	var err error
	var c models.Cart
	cartlist, err := c.List()
	if err != nil {
		logx.Error("列表展示失败")
		return nil, err
	}
	
	var cartList []*shenzhou.CartList
	for _, cart := range cartlist {
		list := shenzhou.CartList{
			Title:  cart.Title,
			Image:  cart.Image,
			Price:  float32(cart.Price),
			Desc:   cart.Desc,
			CartId: int64(cart.ID),
		}
		cartList = append(cartList, &list)
	}

	return &shenzhou.CartListResponse{
		List: cartList,
	}, nil
}
